$('document').ready(function(){	
    $('#birth').datepicker({showButtonPanel: true});
	$('#birth').datepicker('option', {dateFormat: 'dd/mm/yy'});
	$( 'textarea#description' ).ckeditor();    
    $.validator.addMethod("logoCheck", function (value, element) {
        return validateLogo();
    }, image_invalid);
	$.validator.addMethod("dateCheck", function (value, element, param) {
        return validateDate($('#birth').val());
    }, birth_invalid);
	$('#frmAdd').validate({
            errorClass      : 'error',
            errorElement	: 'span',
    		onfocusout		: false,
    		onkeyup			: false,
    		ignore			: 'input[type="text"]:hidden',
			rules:{
				first:{
					minlength:VL_NAME_MINLENGTH,
					maxlength:VL_NAME_MAXLENGTH
				},
                last:{
					minlength:VL_NAME_MINLENGTH,
					maxlength:VL_NAME_MAXLENGTH
				},
				nickname:{
					minlength:VL_NAME_MINLENGTH,
					maxlength:VL_NAME_MAXLENGTH
				},
				birth:{
					dateCheck:true
				},
                place:{
					required: true					
				},
               /* logo:{                    
                    logoCheck:true
                },*/
                tag:{
                    maxlength:VL_TAG_MAXLENGTH
                },
                sshort:{
                    minlength: VL_SHORT_MINLENGTH,
                    maxlength: VL_SHORT_MAXLENGTH,
                },
                description:{
                    minlength:VL_CONTENT_MINLENGTH
                },
                type:{
                    required:true
                }                				
			},
			messages:{
                first:{                  
                    minlength: firstname_minlength,
                    maxlength: firstname_maxlength
                },
				last:{
                    minlength: lastname_minlength,
                    maxlength: lastname_maxlength
                },
				nickname:{
                    minlength: nickname_minlength,
                    maxlength: nickname_maxlength
                },
				birth:{
					dateCheck:birth_invalid
				},
				place:{
                    required : national_required                                    
                },
               /* logo:{                    
                    logoCheck:logo_format
                },*/
                sshort:{
                    minlength: short_minlength,
                    maxlength: short_maxlength
                },
                description:{
                    minlength:description_minlength
                }
			},
			errorPlacement: function(error, element) {
			       error.insertAfter(element); // change this to place error message elsewhere
			}			
	});
	$('.valueChange').click(function(){
		getFeature('featureTbl', 'feature');
	});
});
function validateLogo() {
    strLink = $('#link').val();
	strFile = $('#logo').val();
	if(strLink.length <= 0 && strFile.length <= 0) return false;
    if( strFile.length > 0 && strLink.length <=0  && validateImage(strFile) &&  validateImageSize(this,IMAGE_SIZE)) {        
         return true;
    }
	if(strLink.length > 0 && strFile.length <= 0 && validateUrl(strLink)) return true;
    return false;
}
resetLogo = function(type) {
    if(type==1){ $("#logo").replaceWith($("#logo").clone()); return validateUrl($('#link').val());}
    else { $('#link').val('');return validateImage($('#logo').val());}
}
